<template>
	<van-button
		class="follow-btn" 
		color="#3296fa" 
		:type="value?'default':'info'" 
		:loading="loading"
		:icon="value?'':'plus'"
		size="small" 
		round 
		:text="value?'已关注':'关注'"
		@click="handleFollow"
		style="width:60%"
		/>
</template>

<script>
	import { followUser, unFollowUser } from '@/api/user'
	export default {
		name:'followus',
		props:{
			userId:{
				type:[Number,String,Object],
				required:true
			},
			value:{
				type:Boolean,
				required:true
			}
		},
		data(){
			return {
				loading:false
			}
		},
		methods:{
			async handleFollow(){
				this.loading=true
				try{
					if(this.value){
						await unFollowUser(this.userId)
					}else{
						await followUser(this.userId)
					}
					this.$emit('input',!this.value)
				}catch(err){
					console.log(err)
				}
				this.loading=false
			}
		}
	}
</script>

<style scoped lang='less'>
	
</style>
